import state from './states.js'
import mutations from './mutations.js'
import actions from './actions.js'

// 动态加载modlues FOR vue3 and vite
const files = import.meta.globEager('./modules/*.js')
let allDynamicModules = {}
for (const key in files) {
	allDynamicModules[key.replace(/(\.\/modules\/|\.js)/g, '')] = files[key].default
}
// 动态加载modlues VUE3 END

// 动态加载modlues FOR vue2 
// const modulesFiles = require.context('./modules', true, /\.js$/)

// const modules = modulesFiles.keys().reduce((modules, modulePath) => {
//   const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
//   const value = modulesFiles(modulePath)
//   modules[moduleName] = value.default
//   return modules
// }, {})
// 动态加载modlues FOR vue2  End

// #ifndef VUE3
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state,
	modules: allDynamicModules,
	mutations,
	actions
})
// #endif

// #ifdef VUE3
import {
	createStore
} from 'vuex'
const store = createStore({
	state,
	modules: allDynamicModules,
	mutations,
	actions
})
// #endif

export default store